package com.cdu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdu.enums.MessageEnum;
import com.cdu.mapper.SysLogMapper;
import com.cdu.model.common.BaseResponse;
import com.cdu.model.common.PageResult;
import com.cdu.model.query.LogQurey;
import com.cdu.pojo.SysLog;
import com.cdu.service.SysLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.logging.LogManager;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chengjiang@jasonch.tech
 * @since 2022-05-10
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {
    @Autowired
    private final SysLogMapper sysLogMapper;

    //查询所有日志
    @Override
    public BaseResponse queryAllLogs(LogQurey logQurey) {
        PageHelper.startPage(logQurey.getPageNum(),logQurey.getPageSize());
        List<SysLog> logList = sysLogMapper.selectList(null);
        var pageInfo = PageInfo.of(logList);
        return BaseResponse.response(PageResult.doPage(pageInfo.getList(),
                pageInfo.getPageNum(),
                pageInfo.getPageSize(),
                pageInfo.getTotal()), MessageEnum.SUCCESS);
    }
}
